<?php
namespace app\shop\model;

use app\BaseModel;
use think\facade\Db;
use app\shop\model\IndexCompany;
class IndexUserInfo extends BaseModel
{
	//定义表名

	protected $name = 'longbing_card_user_info';

    /**
     * @var array
     * 查询器
     */
    protected $append = [
        'my_company_text',
    ];

    /**
     * @param $value
     * @param $data
     * @return mixed
     * 状态
     */
    public function getMyCompanyTextAttr($value,$data){
        $company_model = new IndexCompany();
        if(!empty($data['company_id'])){
            $dis[] = ['uniacid','=',$data['uniacid']];
            $dis[] = ['id','=',$data['company_id']];
            $dis[] = ['status','=',1];
            $company = $company_model->getCompany($dis);
        }
        if(empty($data['company_id'])||empty($company)){
            $where[] = ['uniacid','=',$data['uniacid']];
            $where[] = ['status','=',1];
            $company = $company_model->getCompany($where);
        }
        return $company;
    }

    /**
     * @param $dis
     * @return array|string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 获取用户信息
     */
	public function userInfo($dis){
	    $data = $this->where($dis)->find();
	    return !empty($data)?$data->toArray():'';

    }

    /**
     * @param $dis
     * @return mixed
     * 获取公司id
     */

    public function getCompanyId($dis,$uniacid = ''){
	   $data = $this->where($dis)->value('company_id');
	   if(empty($data)){
           $data = $this->where(['uniacid'=>$uniacid])->value('company_id');
       }
	   return $data;
    }

}